from tortoise import fields
from tortoise.models import Model


class SysConfig(Model):
    variable = fields.CharField(max_length=128, description="变量", pk=True)
    value = fields.CharField(null=True, max_length=128, description="值")
    set_time = fields.DatetimeField(description="设置时间", auto_now_add=True)

    class Meta:
        table = "sys_config"
        table_description = "系统配置"


class User(Model):
    id = fields.IntField(pk=True)
    mobile = fields.CharField(max_length=11, unique=True, Index=True, null=True, description="手机号")
    nickname = fields.CharField(max_length=10, unique=True, description="昵称")
    avatar = fields.CharField(max_length=255, default=" ", description="头像")

    class Meta:
        table = "user"
        table_description = "用户"


class UserInfo(Model):
    id = fields.IntField(pk=True)
    interest_tags = fields.CharField(max_length=255, null=True, description="兴趣标签")
    is_master = fields.BooleanField(default=False, description="是否是大师")
    style = fields.CharField(max_length=255, null=True, description="擅长风格")
    house_type = fields.CharField(max_length=255, null=True, description="擅长户型")
    name = fields.CharField(max_length=60, null=True, description="姓名")
    position = fields.CharField(max_length=20, null=True, description="职位")
    gender = fields.IntField(default=0, description="性别 0 默认 1 男性 2 女性")
    birthday = fields.DateField(null=True, description="生日")
    city = fields.CharField(max_length=8, null=True, description="城市编号")
    city_name = fields.CharField(max_length=50, null=True, description="城市名称（省市区）")
    country = fields.CharField(max_length=20, null=True, description="国家")
    personal_profile = fields.CharField(max_length=200, null=True, description="个人简介")
    personal_profile_image = fields.TextField(null=True, description="大师图文简介")
    follow_number = fields.IntField(default=0, description="关注数")
    fan_number = fields.IntField(default=0, description="粉丝数")
    browse_number = fields.IntField(default=0, description="浏览数")
    collect_number = fields.IntField(default=0, description="收藏数")
    custom_tags = fields.TextField(null=True, description="自定义标签")
    step = fields.IntField(default=1, description="1-没被邀请 2-没选兴趣标签 3-进入首页")
    registration_id = fields.CharField(max_length=50, null=True, description="推送设备号")
    app_version = fields.CharField(max_length=10, null=True, description="app版本号")

    class Meta:
        table = "user_info"
        table_description = "用户信息"


class UserSearch(Model):
    id = fields.IntField(pk=True)
    words = fields.CharField(max_length=1000, null=True, description="历史搜索词")

    class Meta:
        table = "user_search"
        table_description = "用户搜索信息"


class Photo(Model):
    id = fields.IntField(pk=True)
    system_tags = fields.CharField(max_length=255, null=True, description="一组系统标签")
    origin = fields.CharField(max_length=255, null=True, description="来源")
    text = fields.TextField(null=True, description="正文")
    key = fields.CharField(max_length=255, null=True, description="文件名称")
    width = fields.IntField(null=True, description="宽")
    height = fields.IntField(null=True, description="高")
    file_size = fields.IntField(null=True, description="文件大小")
    file_exif = fields.TextField(null=True, description="文件属性exif")
    space = fields.CharField(max_length=50, null=True, description="空间")
    style = fields.CharField(max_length=255, null=True, description="风格")
    house_type = fields.CharField(max_length=255, null=True, description="户型")
    color_values = fields.CharField(max_length=255, null=True, description="一组颜色")

    class Meta:
        table = "photo"
        table_description = "图片"


class Case(Model):
    id = fields.IntField(pk=True)
    kind = fields.IntField(description="类型 1-轮播 2-图文")
    system_tags = fields.CharField(max_length=255, null=True, description="一组系统标签")
    title = fields.CharField(max_length=255, description="标题")
    origin = fields.CharField(max_length=255, null=True, description="来源")
    text = fields.TextField(null=True, description="正文")
    style = fields.CharField(max_length=255, null=True, description="风格")
    house_type = fields.CharField(max_length=255, null=True, description="户型")
    cover = fields.CharField(max_length=255, null=True, description="封面")

    class Meta:
        table = "case"
        table_description = "案例"


class Video(Model):
    id = fields.IntField(pk=True)
    system_tags = fields.CharField(max_length=255, null=True, description="一组系统标签")
    text = fields.CharField(max_length=500, null=True, description="正文")
    key = fields.CharField(max_length=255, null=True, description="文件名称")
    width = fields.IntField(null=True, description="宽")
    height = fields.IntField(null=True, description="高")
    duration = fields.CharField(max_length=15, null=True, description="时长")
    file_size = fields.IntField(null=True, description="文件大小")
    file_exif = fields.TextField(null=True, description="文件属性exif")

    class Meta:
        table = "video"
        table_description = "视频"


class Panorama(Model):
    id = fields.IntField(pk=True)
    url = fields.CharField(max_length=255, null=True, description="链接地址")
    text = fields.CharField(max_length=500, null=True, description="正文")
    key = fields.CharField(max_length=255, null=True, description="文件名称")
    width = fields.IntField(null=True, description="宽")
    height = fields.IntField(null=True, description="高")
    file_size = fields.IntField(null=True, description="文件大小")
    file_exif = fields.TextField(null=True, description="文件属性exif")

    class Meta:
        table = "panorama"
        table_description = "3D全景"


class Media(Model):
    id = fields.IntField(pk=True)
    object_type = fields.IntField(description="对象类型 1-图片 2-案例 4-视频 5-3D全景")
    object_id = fields.IntField(description="对象编号")
    created_time = fields.DatetimeField(description="发布时间", auto_now_add=True)
    user_id = fields.IntField(description="用户编号")
    comment_number = fields.IntField(default=0, description="评论数量")
    like_number = fields.IntField(default=0, description="点赞数量")
    collect_number = fields.IntField(default=0, description="收藏数量")
    is_house_case = fields.BooleanField(default=False, description="是否是全屋案例")
    is_delete = fields.BooleanField(default=False, description="是否被删除")
    is_recommend = fields.BooleanField(default=False, description="是否被推荐")
    recommend_time = fields.DatetimeField(null=True, description="推荐时间")
    parent_id = fields.IntField(default=0, description="父亲媒体编号")

    class Meta:
        table = "media"
        table_description = "媒体"

    class Type:
        photo: int = 1
        case: int = 2
        video: int = 4
        panorama: int = 5


class MediaCustomTag(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号")
    media_id = fields.IntField(description="媒体编号")
    tags = fields.CharField(max_length=255, null=True, description="一组自定义标签")

    class Meta:
        table = "media_custom_tag"
        table_description = "媒体自定义标签"


class MyMedia(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号")
    media_id = fields.IntField(description="媒体编号")
    created_time = fields.DatetimeField(description="添加时间", auto_now_add=True)

    class Meta:
        table = "my_media"
        table_description = "我的图片"
        unique_together = ("user_id", "media_id")


class Collect(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号")
    media_id = fields.IntField(description="媒体编号")
    created_time = fields.DatetimeField(description="收藏时间", auto_now_add=True)

    class Meta:
        table = "collect"
        table_description = "收藏记录"
        unique_together = ("user_id", "media_id")


class Comment(Model):
    id = fields.IntField(pk=True)
    object_id = fields.IntField(description="评论对象编号")
    user_id = fields.IntField(description="用户编号")
    created_time = fields.DatetimeField(description="发布时间", auto_now_add=True)
    text = fields.CharField(max_length=255, null=True, description="正文")
    reply_revert_comment_id = fields.IntField(default=0, description="被回复评论编号")
    reply_revert_comment_user_id = fields.IntField(default=0, description="被回复评论者编号")
    stair_reply_comment_id = fields.IntField(default=0, description="一级被回复评论编号")
    comment_number = fields.IntField(default=0, description="被评论数量")
    object_comment_id = fields.IntField(null=True, description="评论对象所属者回复评论的编号")
    like_number = fields.IntField(default=0, description="点赞数量")

    class Meta:
        table = "comment"
        table_description = "评论表"


class Like(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号")
    media_id = fields.IntField(description="媒体编号")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="点赞时间")

    class Meta:
        table = "like"
        table_description = "点赞表"
        unique_together = ("user_id", "media_id")


class Folder(Model):
    """
    文件夹
        采用Path Enumerations格式存储
    """
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号")
    name = fields.CharField(max_length=40, description="名称")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="创建时间")
    media_number = fields.IntField(default=0, description="媒体个数")
    sum_media_number = fields.IntField(default=0, description="总媒体个数")
    parent_folder_id = fields.IntField(default=0, description="父文件夹编号")
    description = fields.CharField(max_length=255, default='', description="描述")
    folder_types = fields.IntField(description="文件夹类型 1-收藏夹 2-普通 3-智能")
    filter_condition = fields.CharField(max_length=255, default='', description="筛选条件")
    level = fields.IntField(default=0, description="层级")
    path = fields.CharField(max_length=255, default='', description="路径，格式：/1/2/3")
    parent_path = fields.CharField(max_length=255, default='', description="父级路径，格式：/1/2")

    class Meta:
        table = "folder"
        table_description = "文件夹"

    class Type:
        collect = 1
        common = 2
        smart = 3


class FolderCovers(Model):
    """"""
    id = fields.IntField(pk=True)
    covers = fields.TextField(default='', description="封面列表")

    class Meta:
        table = "folder_covers"
        table_description = "文件夹封面列表"


class FolderFile(Model):
    id = fields.IntField(pk=True)
    folder_id = fields.IntField(description="文件夹编号")
    media_id = fields.IntField(description="媒体编号")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="创建时间")
    user_id = fields.IntField(default=0, description="用户编号")

    class Meta:
        table = "folder_file"
        table_description = "文件夹文件"


class Message(Model):
    id = fields.IntField(pk=True)
    title = fields.CharField(max_length=30, description="标题")
    message = fields.CharField(max_length=255, description="消息")
    user_id = fields.IntField(description="用户编号")
    message_kind = fields.IntField(description="消息类型  1-推荐 2-系统")
    message_classification = fields.IntField(default=0, description="消息分类")
    is_push = fields.BooleanField(default=True, description="是否推送")
    is_already_push = fields.BooleanField(default=False, description="是否已推送")
    is_read = fields.BooleanField(default=False, description="是否阅读")
    is_delete = fields.BooleanField(default=False, description="是否删除")
    message_params = fields.CharField(max_length=255, description="消息参数")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="创建时间")

    class Meta:
        table = "message"
        table_description = "消息"


class RecycleBin(Model):
    id = fields.IntField(pk=True)
    folder_id = fields.IntField(description="文件夹编号")
    media_id = fields.IntField(description="媒体编号")
    created_time = fields.DatetimeField(null=True, description="创建时间")
    user_id = fields.IntField(default=0, description="用户编号")
    deleted_time = fields.DatetimeField(null=True, auto_now_add=True, description="删除时间")

    class Meta:
        table = "recycle_bin"
        table_description = "回收站"


class BrowseHistory(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="浏览时间")
    media_id = fields.IntField(description="媒体编号编号")

    class Meta:
        table = "browse_history"
        table_description = "浏览记录"


class Follow(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="关注者")
    follow_user_id = fields.IntField(description="被关注者")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="关注时间")

    class Meta:
        table = "follow"
        table_description = "关注列表"
        unique_together = ("user_id", "follow_user_id")


class CommentLike(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户编号", index=True)
    comment_id = fields.IntField(description="评论编号")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="点赞时间")

    class Meta:
        table = "comment_like"
        table_description = "评论点赞表"
        unique_together = ("user_id", "comment_id")


class Menu(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=40, description="名称")
    parent_id = fields.IntField(default=0, description="父编号")
    sort = fields.IntField(default=0, description="同级排序")
    level = fields.IntField(default=0, description="层级")
    path = fields.CharField(max_length=255, default='', description="路径，格式：/1/2/3")
    parent_path = fields.CharField(max_length=255, default='', description="父级路径，格式：/1/2")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="创建时间")

    class Meta:
        table = "menu"
        table_description = "菜单表"


class RecommendUser(Model):
    id = fields.IntField(pk=True)
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="推荐时间")

    class Meta:
        table = "recommend_user"
        table_description = "推荐用户表"


class Ad(Model):
    id = fields.IntField(pk=True)
    title = fields.CharField(max_length=100, description="名称")
    place_id = fields.IntField(description="广告位置编号")
    url = fields.CharField(max_length=255, description="链接")
    description = fields.CharField(max_length=255, description="描述")
    key = fields.CharField(max_length=255, null=True, description="文件名称")
    width = fields.IntField(default=0, description="宽")
    height = fields.IntField(default=0, description="高")
    file_exif = fields.TextField(default='', description="文件属性exif")
    sort = fields.IntField(default=0, description="同级排序")
    enable = fields.BooleanField(default=True, description="是否启用")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="创建时间")

    class Meta:
        table = "ad"
        table_description = "广告表"


class AdPlace(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100, description="名称")
    description = fields.CharField(max_length=255, description="描述")
    created_time = fields.DatetimeField(null=True, auto_now_add=True, description="创建时间")

    class Meta:
        table = "ad_place"
        table_description = "广告位置表"
